package cn.com.spic.demo.controller;

import com.alibaba.fastjson.JSONObject;
import com.yonyou.apigateway.ApiGatewayService;
import com.yonyou.yht.web.cas.util.CasClientUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/permission")
public class PermissionController {

    @Autowired
    private ApiGatewayService apiGatewayService;

    //获取用户信息
    @RequestMapping("/getUserInfo")
    public JSONObject getUserInfo() {
        // String path="coframe/agent/ext/user/me";
        // Map<String, String> headerParams=Maps.newHashMap();
        // headerParams.put("username", String.valueOf(map.get("userCode")));
        // //headerParams.put("username", "11874284");
        // return apiGatewayService.doGet(path, null, headerParams);
        JSONObject userInfo = new JSONObject();
        if(CasClientUtils.getLoginedUserAttributes()!=null){
            userInfo.put("code", 200);
            userInfo.put("data", CasClientUtils.getLoginedUserAttributes());
        }else {
            userInfo.put("code", 500);
            userInfo.put("data", "Error");
        }

        return userInfo;
    }

    @RequestMapping("/getGrantedMenus")
    public Map<String, Object> getGrantedMenus() {
        // String path = "coframe/agent/user-accounts/" + userId + "/granted-menus";
        // Map<String, String> headerParams = Maps.newHashMap();
        // return apiGatewayService.doGet(path, null, headerParams);
		return null;
    }

}
